﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for AdminDAL
/// </summary>
public class AdminDAL
{
    DABasic _daBasic;
    public AdminDAL()
    {
        _daBasic = new DABasic();
    }

    internal int AddRoute(int originID, int destinationID, double flyHour)
    {
        string _command = "_Admin_AddRoute";

        SqlParameter[] _para2 = new SqlParameter[4];
        _para2[0] = new SqlParameter("@OriginalCityID", System.Data.SqlDbType.Int);
        _para2[0].Value = originID;
        _para2[1] = new SqlParameter("@DestinationCityID", System.Data.SqlDbType.Int);
        _para2[1].Value = destinationID;
        _para2[2] = new SqlParameter("@FlyHour", System.Data.SqlDbType.Float);
        _para2[2].Value = flyHour;
        _para2[3] = new SqlParameter("@routid", System.Data.SqlDbType.Int);
        _para2[3].Direction = System.Data.ParameterDirection.Output;

        SqlParameterCollection col = _daBasic.ExecuteReturnParameters(_command, _para2, System.Data.CommandType.StoredProcedure);
        return Convert.ToInt32(col["@routid"].Value);

    }

    internal void AddSchedule(int routeid, string dayofWeek, string time)
    {
        string _command = "INSERT INTO Airline_Schedule (DepartTime, RouteID, DayofWeek) VALUES (@DepartTime,@RouteID,@DayofWeek)";

        SqlParameter[] _para2 = new SqlParameter[3];
        _para2[0] = new SqlParameter("@DepartTime", System.Data.SqlDbType.VarChar, 50);
        _para2[0].Value = time;
        _para2[1] = new SqlParameter("@RouteID", System.Data.SqlDbType.Int);
        _para2[1].Value = routeid;
        _para2[2] = new SqlParameter("@DayofWeek", System.Data.SqlDbType.VarChar, 50);
        _para2[2].Value = dayofWeek;

        _daBasic.ExecuteReturnParameters(_command, _para2, System.Data.CommandType.Text);

    }

    internal void AddPlane(string Name, int BusSeat, int FirstSeat, int ClubtSeat)
    {
        string _command = "INSERT INTO Airline_Airplane ([Plane Name], [Total Bussiness Class Seats], [Total First Class Seats], [Total Club Class Seats]) VALUES (@Name,@Bus,@First,@Club)";

        SqlParameter[] _para2 = new SqlParameter[4];
        _para2[0] = new SqlParameter("@Name", System.Data.SqlDbType.VarChar,50);
        _para2[0].Value = Name;
        _para2[1] = new SqlParameter("@Bus", System.Data.SqlDbType.Int);
        _para2[1].Value = BusSeat;
        _para2[2] = new SqlParameter("@First", System.Data.SqlDbType.Int);
        _para2[2].Value = FirstSeat;
        _para2[3] = new SqlParameter("@Club", System.Data.SqlDbType.Int);
        _para2[3].Value = ClubtSeat;

        _daBasic.ExecuteReturnParameters(_command, _para2, System.Data.CommandType.Text);
    }
}
